var addon = require('../build/Release/addon')
var env = require('./env')

var mapName = env.file_mapping_name;
var bufSize = env.image_width*env.image_height;

var fileMap = new addon.FileMap();
var buf = fileMap.create(mapName,bufSize);

const sleep = (interval) => {
    return new Promise(resolve => {
        setTimeout(resolve, interval);
    })
}

const setValue = (value) => {
   for(var i=0;i<1024*1024;i++){
       buf[i] = value;
   }
}

(async () => {
  let value = 0;
  while(true)
  {
    setValue(value);
    await sleep(5);
    value += 1;
    if(value == 256) value=0;
  }
})();

var stdin = process.openStdin();
stdin.resume(); 